package edu.cebanc.spring.biblioteca.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import edu.cebanc.spring.biblioteca.domain.Genero;

@Repository("generosDAO")
public class GenerosDAOImpl implements GenerosDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Genero> listGeneros() {
		// TODO Auto-generated method stub
		return (List<Genero>)sessionFactory.getCurrentSession().createCriteria(Genero.class).list();
	}

	@Override
	public void saveGenero(Genero genero) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().saveOrUpdate(genero);
	}

	@Override
	public Genero getGenero(int id) {
		// TODO Auto-generated method stub
		return (Genero)sessionFactory.getCurrentSession().load(Genero.class, id);
	}

	@Override
	public void deleteGenero(Genero genero) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().delete(genero);
	}

}
